package com.esunny.resourcevisualization;

import org.activiti.spring.boot.SecurityAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;

/**
 * 项目启动入口
 */
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@EnableScheduling
public class ResourceVisualizationApplication {

    private final static Logger log = LoggerFactory.getLogger(ResourceVisualizationApplication.class);

    public static void main(String[] args) {
        try {
            System.setProperty("spring.devtools.restart.enabled", "false");
            SpringApplication app = new SpringApplication(ResourceVisualizationApplication.class);
            ConfigurableApplicationContext con = app.run(args);
            Environment env = con.getEnvironment();
            String protocol = "http";
            if (env.getProperty("server.ssl.key-store") != null) {
                protocol = "https";
            }

            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            String path = env.getProperty("server.servlet.context-path");
            path = path == null ? "" : path;
            log.info("\n----------------------------------------------------------\n\t" +
                    "Application {} is running! Access URLs:\n\t" +
                    "本地访问地址: \t{}://localhost:{}{}/\n\t" +
                    "外部访问地址: \t{}://{}:{}{}/\n\t" +
                    "Swagger文档: \t{}://{}:{}{}/swagger-ui.html\n\t" +
                    "Profile()s: \t{}\n" +
                    "----------------------------------------------------------",
                    env.getProperty("server.name"),
                    protocol,port,path,
                    protocol,ip,port,path,
                    protocol,ip,port,path,
                    env.getActiveProfiles());
        } catch (Exception e) {
            log.error("项目启动异常",e);
        }

    }
}
